Skip to main content

Rotations

You will solve the exercise starting from the file rotations.c located in the directory drills/tasks/rotations/.

Implement left and right rotations for 32-bit integers in C.

TIP: The rotation operation (also known as circular shift) is similar to the shift operation, with the only difference being that the empty space generated by the shift is filled with the discarded bit.

Example of left rotation by one bit:

Left Logical Rotation

NOTE:

rotate_left(0x80000000, 1)   = 1
rotate_right(0x00000001, 16) = 65536

If you're having difficulties solving this exercise, go through this reading material.